package com.nageoffer.shortlink.admin.controller;

import com.nageoffer.shortlink.admin.dao.entity.Group;
import com.nageoffer.shortlink.common.dto.admin.req.GroupCreateReqDTO;
import com.nageoffer.shortlink.common.dto.admin.req.GroupSortReqDTO;
import com.nageoffer.shortlink.common.dto.admin.req.GroupUpdateReqDTO;
import com.nageoffer.shortlink.common.dto.admin.resp.GroupGetRespDTO;
import com.nageoffer.shortlink.admin.service.GroupService;
import com.nageoffer.shortlink.common.convention.result.Result;
import com.nageoffer.shortlink.common.convention.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/short-link/admin/group")
@RequiredArgsConstructor
public class GroupController {
    private final GroupService groupService;

    @PostMapping
    public Result<Void> saveGroup(@RequestBody GroupCreateReqDTO requestParam){
        groupService.saveGroup(requestParam);
        return Results.success();
    }
    @GetMapping
    public Result<List<GroupGetRespDTO>> getGroups(){
        return Results.success(groupService.getGroups());
    }

    @GetMapping("/simple")
    public Result<List<Group>> getSimpleGroups(){
        return Results.success(groupService.getSimpleGroups());
    }

    @PutMapping
    public Result<Void> updateGroup(@RequestBody GroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }
    @DeleteMapping
    public Result<Void> deleteGroup(@RequestParam String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }

    @PutMapping("/sort-group")
    public Result<Void> sortGroup(@RequestBody List<GroupSortReqDTO> requestParam){
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
